package org.freedoit.server.service.auth;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.freedoit.common.data.DefaultFreeDoitResponse;
import org.freedoit.common.util.FreeDoitDataUtils;

public class ExceptionHandlerServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1906298542516433980L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
		Object obj = request.getAttribute( "javax.servlet.error.exception" );
		if (obj != null) {
			Exception e = (Exception)obj;
			e.printStackTrace();
		} else {
			System.err.println("Cannot find exception");
		}

		response.getWriter().write(FreeDoitDataUtils.createStandardJson().toJson(new DefaultFreeDoitResponse(DefaultFreeDoitResponse.CODE_SERVER_ERROR), 
				new com.google.gson.reflect.TypeToken<DefaultFreeDoitResponse>() {}.getType()));
		
	}

}
